package com.hot100.mid;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 盛最多水的容器
 * @date 2022/7/31 11:58
 */
public class Demo04 {
    public static void main(String[] args) {
         int[] num={1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(num));
    }

    public static int maxArea1(int[] height) {
       int max=0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i+1; j <height.length ; j++) {
                int min=Math.min(height[i],height[j]);
                max=Math.max(max,min*(j-i));
            }
        }
        return max;
    }
    //从最大底开始，此时底最大，高决定面积大小，然后左右开始缩进，哪一边的高底，哪一边就开始缩进
    public static int maxArea(int[] height) {
        int area=0;
        if(height.length<=1){
            return 0;
        }
        int left=0,right=height.length-1;
        while (left<right){
            area=Math.max(area,Math.min(height[left],height[right])*(right-left));
            if (height[left]<height[right]) {
                left++;
            }else {
                right--;
            }

        }
        return area;
    }
}
